package com.hzx.ssm.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hzx.ssm.entity.Message;
import com.hzx.ssm.entity.Notice;
import com.hzx.ssm.entity.ResBean;
import com.hzx.ssm.service.NoticeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;


@Controller
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    //    添加管理员通知
    @ApiOperation("管理员发布一条新通知")
    @PostMapping(value = "addNotice")
    @ResponseBody
    public ResBean addNotice(Notice notice) {
        noticeService.addNotice(notice);
        return ResBean.sucess(200, "添加通知成功");
    }

    //根据Id删除通知
    @ApiOperation("管理员根据id删除一条通知")
    @DeleteMapping(value = "deleteNoticeById")
    @ResponseBody
    public ResBean deleteNoticeById(@RequestParam("notice_id") String notice_id) {
        noticeService.deleteNoticeById(notice_id);
        return ResBean.sucess(200, "删除通知成功");
    }

    @ApiOperation("管理员根据id修改通知内容")
    @PutMapping(value = "updateNoticeById")
    @ResponseBody
    public ResBean updateNoticeById(Notice notice) {
        noticeService.updateNoticeById(notice);
        return ResBean.sucess(200, "更新通知成功");
    }

    @ApiOperation("查找所有通知（不需要token）")
    @GetMapping(value = "findAll")
    @ResponseBody
    public ResBean findAll(@RequestParam("pageNum") Integer pageNum, @RequestParam("sizeNum") Integer sizeNum) {

        return ResBean.sucess(200, "查找所有通知成功", noticeService.findAll(pageNum, sizeNum));

    }


}
